<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>去向表页面</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>
</head>
<body>

	<!-- 在页面中使用easy ui组件进行界面编程 -->
	<!-- 数据表格组件 -->
	<table id="position_dg" title="去向管理" class="easyui-datagrid"
		style="width: 700px; height: 500px"
		url="${param.request.contextPath}/position/list"
		toolbar="#position_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<!-- field="goId"要对应实体类 -->
				<th field="stuId" formatter="stuFormatter"  width="50">学号</th>
				<th field="place" width="50">地点</th>
				<th field="outTime" width="50">离校时间</th>
				<th field="goTime" width="50">返校时间</th>
			</tr>
		</thead>
	</table>

	<!-- 工具条组件 -->
	<div id="position_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newPosition()">新增去向</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editPosition()">修改去向</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyPosition()">删除去向</a>
	</div>

	<!-- 新增和修改表单 start-->
	<div id="position_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#position_dlg-buttons">
		<div class="ftitle">去向管理</div>
		<form id="position_fm" method="post">
			<div class="fitem">
				<!-- name="admName"要和实体类名称一致 -->
				<label> 学号:</label> <input name="stuId" class="easyui-validatebox"
					required="true">
			</div>
			<div class="fitem">
				<!-- name="admPassword"要和实体类名称一致 -->
				<label> 地点:</label> <input name="place" class="easyui-validatebox"
					required="true">
			</div>
			<div class="fitem">
				<!-- name="admPassword"要和实体类名称一致 -->
				<label>离校时间:</label> <input name="outTime"
					class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<!-- name="admPassword"要和实体类名称一致 -->
				<label>返校时间:</label> <input name="goTime" class="easyui-validatebox"
					required="true">
			</div>
		</form>
	</div>

	<div id="position_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="savePosition()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#position_dlg').dialog('close')">取消</a>
	</div>
	<!-- 新增和修改表单 end-->

	<script type="text/javascript">
		//easy UI在处理多列数据时，需要使用格式化解析器
		function stuFormatter(value, row, index) {
			if(row.student == null){
				return null;
			}
			return row.student.stuId;
		}
		function positionFormatter(value,row,index){
			return row.position.place
			}
		function positionFormatter(value,row,index){
			return row.position.outTime
			}
		function positionFormatter(value,row,index){
			return row.position.goTime
			}
		
		function newPosition() {
			$('#position_dlg').dialog('open').dialog('setTitle', '新增去向');
			$('#position_fm').form('clear');
			url = '${param.request.contextPath}/position/add';
		}
		function editPosition() {
			var row = $('#position_dg').datagrid('getSelected');
			if (row) {
				$('#position_dlg').dialog('open').dialog('setTitle', '修改去向');
				$('#position_fm').form('load', row);
				url = '${param.request.contextPath}/position/edit?goId='
						+ row.goId;
			}
			console.log(row.goId);
		}
		function destroyPosition(){
			var row = $('#position_dg').datagrid('getSelected');
			if(row){
				$.messager.confirm('Confirm','是否删除该去向？',function(r){
					if(r){
						$.post('${param.request.contextPath}/position/delete',{
							goId:row.goId
							},function(result){
								if(result.success){
									$('#position_dg').datagrid('reload');
									}else{
										$.messager.show({
											title:'提示',
											msg:result.errorMsg
											});
										}
								},'json');
						}
					});
				}
			}
		function savePosition(){
			$('#position_fm').form('submit',{
				url:url,
				onSubmit:function(){
					return $(this).form('validate');
					},
					success : function(result){
						var result = eval('('+result+')');
						if(result.errorMsg){
							$.messager.show({
								title : '提示',
								msg : result.errorMsg
								});
							}else{
								$('position_dlg').dialog('close');
								$('position_dg').datagrid('reload');
								}
						}
				});
			}

		/* //easy UI在处理多列数据时，需要使用格式化解析器
		//value是传递进来的admin对象，row是当前行数据，index是第几行数据
		function positionFormatter(value,row,index){
			return row.position.
			}
		 */
	</script>




</body>
</html>